import flask
from flask import Flask
from datetime import timedelta
import configparser
import os

from page_front import page_front
from page_upload import page_upload
from page_login import page_login
from page_briefing import page_briefing
from page_register import page_register
from page_myinfo import page_myinfo
from page_history import page_history

config = configparser.ConfigParser()

if __name__ == '__main__':
    # 创建Flask App对象
    app = Flask(__name__, template_folder='./')

    # 注册蓝图
    app.register_blueprint(page_front)
    app.register_blueprint(page_upload)
    app.register_blueprint(page_login)
    app.register_blueprint(page_briefing)
    app.register_blueprint(page_register)
    app.register_blueprint(page_myinfo)
    app.register_blueprint(page_history)

    # 配置
    config.read('config.cfg', encoding='utf-8')
    os.system('cd ' + config.get('App', 'proj_dir'))
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = timedelta(seconds=1)
    app.secret_key = config.get('App', 'key')

    # 运行服务
    app.run(host=config.get('App', 'host'), port=config.get('App', 'port'))
